package TeatCase;

import android.support.test.uiautomator.UiObject2;
import android.util.Log;
import org.junit.Assert;
import org.junit.Test;
import java.util.List;
import QunarTest.QuanrTestCase;
import util.UIHelper;
import static HomeElements.Action.*;
import static HomeElements.AssertElementsContent.*;
import static org.junit.Assert.*;
import static HomeElements.ZuiJinGuanZhuData.*;

/**
 * Created by zhe.xiao on 2017/6/27.
 */


public class TestZuiJinGuanZhu extends QuanrTestCase {

    @Override
    public void setUp() {
        super.setUp();
        UIHelper.getHomeElements().getRecomendTime().init();
    }

    /**
     * 测试最近关注更多跳转
     */
    @Test
    public void testZuiJinMore() {
        UIHelper.getElementsAction().click(UIHelper.getHomeElements().getRecomendTime().getMore());
        String td = zuiJinGuanZhuDes();
        Log.v("UIAUTOMATOR", "testZhuiJinMore: " + td);
        assertEquals(td, "全部关注");
    }

    /**
     * 最近关注：酒店类型
     */
//    @Test
    public void testZuiJinGuanZhuHotel() {
        for (int i = 0; i < 4; i++) {
            zuiJinGuanZhuHotel();
        }
        swipeZuiJinGuanZhu1();
        String mon1 = zuiJinGuanZhu1Mon();
        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuHoteltd1 mon1: " + mon1);
        assertFalse(mon1 == "0");
        assertFalse(mon1 == "0.0");
        String so1 = zuiJinGuanZhu1Sou();
        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuHoteltd1 so1: " + so1);
        assertFalse(so1 == "0分");
        assertFalse(so1 == "0.0分");
        String title1 = zuiJinGuanZhu1Tile();
        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuHoteltd1 title1: " + title1);
        clickZuiJinGuanZhu1();
        String td = zuiJinGuanZhuHotelDes();
        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuHoteltd1: " + td);
        assertEquals(td, title1);
        back();
        String mon2 = zuiJinGuanZhu2Mon();
        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuHoteltd1 mon2: " + mon2);
        assertFalse(mon2 == "0");
        assertFalse(mon2 == "0.0");
        String so2 = zuiJinGuanZhu2Sou();
        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuHoteltd1 so2: " + so2);
        assertFalse(so2 == "0分");
        assertFalse(so2 == "0.0分");
        String title2 = zuiJinGuanZhu2Tile();
        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuHoteltd1 title2: " + title2);
        clickZuiJinGuanZhu2();
        String td1 = zuiJinGuanZhuHotelDes();
        assertEquals(td1, title2);
    }

    /**
     * 最近关注：门票类型
     */
//    @Test
    public void testZuiJinGuanZhuTicket() {
//        for(int i=0; i<4; i++){
//        zuiJinGuanZhuTicket();}
        swipeZuiJinGuanZhu1();
        String mon1 = zuiJinGuanZhu1Mon();
        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuTickettd1: " + mon1);
        assertFalse(mon1 == "0");
        assertFalse(mon1 == "0.0");
        String so1 = zuiJinGuanZhu1Sou();
        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuTickettd1: " + so1);
        assertFalse(so1 == "0分");
        assertFalse(so1 == "0.0分");
        String title1 = zuiJinGuanZhu1Tile();
        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuTickettd1: " + title1);
        clickZuiJinGuanZhu1();
        String td = zuiJinGuanZhuTicketDes();
        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuTickettd1: " + td);
        assertEquals(td, title1);
//        back();
//        String mon2 = zuiJinGuanZhu2Mon();
//        assertFalse(mon2 == "0");
//        assertFalse(mon2 == "0.0");
//        String so2 = zuiJinGuanZhu2Sou();
//        assertFalse(so2 == "0分");
//        assertFalse(so2 == "0.0分");
//        String title2 = zuiJinGuanZhu2Tile();
//        clickZuiJinGuanZhu2();
//        String td1 = zuiJinGuanZhuTicketDes();
//        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuTickettd2: " + td1);
//        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuTickettitle2: " + title2);
//        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuTicketmon2: " + mon2);
//        Log.v("UIAUTOMATOR", "testZuiJinGuanZhuTicketso2: " + so2);
//        assertEquals(td1, title2);
    }

    @Test
    public void testOne() {
        UiObject2 u2 = UIHelper.getHomeElements().getRecomendTime().get1Ele();
        List<String> l = UIHelper.getHomeElements().getRecomendTime().getTag(u2);
        Assert.assertFalse(l.get(1).isEmpty()); //验证标题不为空
        float f = UIHelper.getElementsAction().stringToFloat(l.get(2));
        Assert.assertFalse(f == 0.0f); //验证金额不为0
        if (l.size() == 4) {
            if (l.get(0).equals("门票")) {
                float s = UIHelper.getElementsAction().stringToFloat(l.get(3));
                Assert.assertFalse(s == 0.0f); //验证分数不为0
            }
            if(l.get(0).equals("机票")){
                Assert.assertFalse(l.get(3).isEmpty());
            }
        }
        UIHelper.getElementsAction().click(u2);
        if (l.get(0).equals("门票")) {
            String t = UIHelper.getAssertHome().getRecomendTimeAssert().getTicketName();
            Assert.assertEquals(l.get(1), t);
        }
        if (l.get(0).equals("机票")) {
            String t = UIHelper.getAssertHome().getRecomendTimeAssert().getFlay();
            Assert.assertFalse(t.isEmpty());
        }
        if(l.get(0).equals("酒店")){
            String t = UIHelper.getAssertHome().getRecomendTimeAssert().getHotel();
            Assert.assertEquals(l.get(1), t);
        }
    }

    @Test
    public void testTwo() {
        UiObject2 u2 = UIHelper.getHomeElements().getRecomendTime().get2Ele();
        List<String> l = UIHelper.getHomeElements().getRecomendTime().getTag(u2);
        Assert.assertFalse(l.get(1).isEmpty()); //验证标题不为空
        float f = UIHelper.getElementsAction().stringToFloat(l.get(2));
        Assert.assertFalse(f == 0.0f); //验证金额不为0
        if (l.size() == 4) {
            if (l.get(0).equals("门票") || l.get(0).equals("酒店")) {
                float s = UIHelper.getElementsAction().stringToFloat(l.get(3));
                Assert.assertFalse(s == 0.0f); //验证分数不为0
            }
            if(l.get(0).equals("机票")){
                Assert.assertFalse(l.get(3).isEmpty());
            }
        }
        UIHelper.getElementsAction().click(u2);
        if (l.get(0).equals("门票")) {
            String t = UIHelper.getAssertHome().getRecomendTimeAssert().getTicketName();
            Assert.assertEquals(l.get(1), t);
        }
        if (l.get(0).equals("机票")) {
            String t = UIHelper.getAssertHome().getRecomendTimeAssert().getFlay();
            Assert.assertFalse(t.isEmpty());
        }
        if(l.get(0).equals("酒店")){
            String t = UIHelper.getAssertHome().getRecomendTimeAssert().getHotel();
            Assert.assertEquals(l.get(1), t);
        }
    }
}
